﻿#ifndef TITLEBAR_H
#define TITLEBAR_H

#include <QWidget>
#include <QColor>
#include <QPropertyAnimation>
#include <QRect>
#include <QPushButton>
#include <QMouseEvent>
#include <QStylePainter>
#include <QtWidgets>
#include <QWindow>
#include <QWindowStateChangeEvent>
//自定义的标题栏，可以更为灵活地进行一些操作
//参考豆子的博客 https://tinyurl.com/r75bmk2

namespace Ui {
class TitleBar;
}

//标题栏类
class TitleBar : public QWidget
{
    Q_OBJECT

public:
    explicit TitleBar(QWidget *parent = nullptr, QString title = "title");
    ~TitleBar();
    void setTitle(QString title);

protected:
    void mousePressEvent(QMouseEvent *event) override;
    void mouseDoubleClickEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
private slots:
    void maxButtonClicked();
signals:
    void closeApp();//关闭软件的信号
private:
    Ui::TitleBar *ui;

    QPropertyAnimation* scaleAnimation;//窗口最大化和还原的动画
    QRect lastGeometry;//记录窗口最大化前的位置和大小
    bool isMax;//记录最大化的布尔值
    QPoint clickPos;//记录鼠标点击位置，用于标题栏的拖动
};

#endif // TITLEBAR_H
